package com.mayi.zds.dao;

import com.mayi.zds.dao.provider.UserProvider;
import com.mayi.zds.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * private String id;
 * private String account;
 * private String password;
 * private String email;
 * private String phoneNum;
 * private String role;
 * private BigDecimal money;
 * private String avatar;
 * private String regTime;
 * private String lastloginIp;
 * private Date lastloginTime;
 * private String status;
 * private String userGroup;
 *
 * @ClassName UserDAO
 * @Description TODO
 * @Author zhong
 * @Date 2019/12/24 0024 下午 12:00
 * @Version 1.0
 */
@Repository
public interface UserDAO {

    /**
     * 增加用户
     *
     * @param user
     */
    @Insert("insert into zds_user values(#{id},#{account},#{password},#{email},#{phoneNum},#{role}," +
            "#{money},#{avatar},#{regTime},#{lastloginIp},#{lastloginTime},#{status},#{userGroup})")
    public void add(User user);

    /**
     * 删除用户
     *
     * @param userId
     */
    @Delete("delete from zds_user where id = #{userId}")
    public void del(String userId);

    /**
     * 根据用户id修改用户信息
     *
     * @param user
     */
    @UpdateProvider(type = UserProvider.class,method = "update")
    public void update(User user);

    /**
     * 通过ID查询用户
     *
     * @param userId
     * @return
     */
    @Select("select * from zds_user where id = #{userId}")
    public User getUserById(String userId);

    /**
     * 查询所以用户
     *
     * @return
     */
    @Select("select * from zds_user")
    public List<User> getUsers();

    /**
     * 根据账号和密码查询用户
     *
     * @param account
     * @param password
     * @return
     */
    @Select("select * from zds_user where account=#{param1} and password=#{param2}")
    public User getUserByAccountAndPassword(String account, String password);

    /**
     * 根据account查询用户
     * @param account
     * @return
     */
    @Select("select * from zds_user where account=#{account}")
    public User getUserByAccount(String account);

    /**
     * 查询用户订单数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_order where user_id = #{userId}")
    public int getOrderNum(String userid);

    /**
     * 查询用户完成订单数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_order where user_id = #{userid} and status = '5'")
    public int getSuccessOrderNum(String userid);

    /**
     * 查询用户未使用的优惠券数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_coupon where user_id = #{userid} and status = '1'")
    public int getCouponNum(String userid);
    /**
     * 增加用户
     *
     * @param user
     */
    @Insert("insert into zds_user values(#{id},#{account},#{password},#{email},#{phoneNum},#{role}," +
            "#{money},#{avatar},#{regTime},#{lastloginIp},#{lastloginTime},#{status},#{userGroup})")
    public void add(User user);

    /**
     * 删除用户
     *
     * @param userId
     */
    @Delete("delete from zds_user where id = #{userId}")
    public void del(String userId);

    /**
     * 根据用户id修改用户信息
     *
     * @param user
     */
    @UpdateProvider(type = UserProvider.class,method = "update")
    public void update(User user);

    /**
     * 通过ID查询用户
     *
     * @param userId
     * @return
     */
    @Select("select * from zds_user where id = #{userId}")
    public User getUserById(String userId);

    /**
     * 查询所以用户
     *
     * @return
     */
    @Select("select * from zds_user")
    public List<User> getUsers();

    /**
     * 根据账号和密码查询用户
     *
     * @param account
     * @param password
     * @return
     */
    @Select("select * from zds_user where account=#{param1} and password=#{param2}")
    public User getUserByAccountAndPassword(String account, String password);

    /**
     * 根据account查询用户
     * @param account
     * @return
     */
    @Select("select * from zds_user where account=#{account}")
    public User getUserByAccount(String account);

    /**
     * 查询用户订单数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_order where user_id = #{userId}")
    public int getOrderNum(String userid);

    /**
     * 查询用户完成订单数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_order where user_id = #{userid} and status = '5'")
    public int getSuccessOrderNum(String userid);

    /**
     * 查询用户未使用的优惠券数
     * @param userid
     * @return
     */
    @Select("select count(*) from zds_coupon where user_id = #{userid} and status = '1'")
    public int getCouponNum(String userid);


    public List<Coupon> findCoupon(Coupon coupon);
}
